// pages/myOrder/comps/order-item/order-item.js
import { default_head } from '../../../../utils/config'
import { showModal,showToast } from '../../../../utils/asyncWX'
import { regeneratorRuntime } from '../../../../utils/runtime.js'

import { checkGoods ,payloadOrder } from '../../../../service/public'

Component({
	/**
	 * 组件的属性列表
	 */
	properties: {
		item: {
			type: Object,
			value: {},
		},
	},

	/**
	 * 组件的初始数据
	 */
	data: {
		default_head,
	},

	/**
	 * 组件的方法列表
	 */
	methods: {
		checkGoods() {
			showModal({ content: '确定要进行收货吗？' })
				.then(() => {
					console.log('点击了确定')
          const openid = wx.getStorageSync('openid');
					checkGoods({
						openid: openid || '',
						oid: this.data.item.id,
					}).then(res=>{
            console.log(res);
            if (res.data.err_code === 1000) {
              showToast({title:'收货成功'})
              this.triggerEvent('checkOrder',{state:3})
              return
            }
            showToast({title:'服务器繁忙，请稍后重试'})

            
          })
				})
				.catch(() => {
					console.log('点击了取消')
				})
    },
    payload(){
      const payNum = this.data.item.price * this.data.item.count

      showModal({ content: '您确定要进行支付'+payNum+'元吗？' })
				.then(() => {
          const openid = wx.getStorageSync('openid');
          payloadOrder({
            openid,
            payNum,
            oid:this.data.item.id,

          }).then(res=>{
            if (res.data.err_code == 1000) {
              showToast({title:'付款成功'})
              this.triggerEvent('checkOrder',{state:2})
              return
            }
            showToast({title:'服务器繁忙，请稍后重试'})

       
          })


					
				})
				.catch(() => {
					console.log('点击了取消')
				})

    }
	},
	options: {
		addGlobalClass: true,
	},
})
